<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>报销周期</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<link rel="stylesheet" href="__TMPL__/layui/css/layui.css" media="all">
	<link rel="stylesheet" href="__TMPL__/css/admin.css" media="all">
	<script type="text/javascript" src="__TMPL__/js/jquery.min.js"></script>
	<script type="text/javascript" src="__TMPL__/layui/layui.js"></script>
	<script type="text/javascript" src="__TMPL__/js/admin.js"></script>
    <script type="text/javascript" src="__TMPL__/layui/lay/modules/util.js"></script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" name="loginname" placeholder="请输入关键词" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="time" placeholder="请选择日期">
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <select name="role">
                            <option value="0">管理员</option>
                            <option value="1">超级管理员</option>
                            <option value="2">纠错员</option>
                            <option value="3">采购员</option>
                            <option value="4">推销员</option>
                            <option value="5">运营人员</option>
                            <option value="6">编辑</option>
                        </select><div class="layui-unselect layui-form-select"><div class="layui-select-title"><input type="text" placeholder="请选择" value="管理员" readonly="" class="layui-input layui-unselect"><i class="layui-edge"></i></div><dl class="layui-anim layui-anim-upbit"><dd lay-value="0" class="layui-this">管理员</dd><dd lay-value="1" class="">超级管理员</dd><dd lay-value="2" class="">纠错员</dd><dd lay-value="3" class="">采购员</dd><dd lay-value="4" class="">推销员</dd><dd lay-value="5" class="">运营人员</dd><dd lay-value="6" class="">编辑</dd></dl></div>
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-admin" lay-submit="" lay-filter="LAY-user-back-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                    <button class="layui-btn layuiadmin-btn-admin layui-btn-normal" lay-submit="" lay-filter="add">
                        <i class="layui-icon layui-icon-add-circle-fine layuiadmin-button-btn" style="top: -2px"></i>添加
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <table id="dataTable" lay-filter="dataTable"></table>
            <script type="text/html" id="toolbar">
                <div class="layui-inline"  title="添加" lay-event="add">
                    <i class="layui-icon layui-icon-add-1"></i>
                </div>
                <div class="layui-inline" title="开始" lay-event="begin">
                    <i class="layui-icon layui-icon-triangle-r"></i>
                </div>
                <div class="layui-inline" title="结束" lay-event="end">
                    <i class="layui-icon layui-icon-logout"></i>
                </div>

            </script>
            <script type="text/html" id="status">
                {{# if(d.status == 0){ }}
                <button type="button" class="layui-btn layui-btn-sm">未开始</button>
                {{# }else if(d.status == 1){ }}
                <button type="button" class="layui-btn layui-btn-sm layui-btn-warm">进行中</button>
                {{# }else if(d.status == 2){ }}
                <button type="button" class="layui-btn layui-btn-sm layui-btn-disabled">已完成</button>
                {{# } }}
            </script>
        </div>
    </div>
</div>
<script type="text/html" id="check">
    <input type="radio" name="layTableCheckbox" value="{{d.id}}" lay-filter="check">
</script>
<script>
    layui.config({
        base: '__TMPL__/public/', //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form','admin','upload','table'], function(){
        var $ = layui.$
            ,form = layui.form
            ,admin = layui.admin
            ,table = layui.table;
        form.on('submit(add)', function(data){
            var index = layer.open({
                type: 2
                ,title: '添加报销周期'
                ,content: "/admin/baoxiao_cycle/info"
                ,maxmin: true
                ,area: ['700px', '560px']
                ,btn: ['确定', '取消']
                ,yes: function(index, layero){
                    var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                    submit.click();
                }
            });
            layer.full(index);
        });
        //用户表格初始化
        var dataTable = table.render({
            elem: '#dataTable'
            , url: "{:url('baoxiao_cycle/data')}" //数据接口
            ,toolbar: '#toolbar'
            ,defaultToolbar: ['filter', 'exports', 'print']
            , page: true //开启分页
            , response: {
                statusCode: 1
            }
            , cols: [[ //表头
                {checkbox: true, fixed: true}
                ,{field: 'name', title: "姓名"}
                , {field: 'start_time', title: "开始时间"}
                , {field: 'end_time', title: "结束时间"}
                , {field: 'remark', title: "备注"}
                , {field: 'status', title: "状态", toolbar: '#status'}
            ]]
        });
        table.on('toolbar(dataTable)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            var data1 = obj.data;
            switch(obj.event){
                case 'add':
                    var prop = layer.open({
                        type: 2
                        ,title: '添加周期'
                        ,content: "/admin/expenses/info"
                        ,maxmin: true
                        ,area: ['700px', '560px']
                        ,btn: ['确定', '取消']
                        ,yes: function(index, layero){
                            var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                            submit.click();
                        }
                    });
                    layer.full(prop);
                    break;
                case 'begin':
                    var data = getFirst(checkStatus.data);
                    admin.req({
                        url: "{:url('baoxiao_cycle/modify_status')}",
                        method:'post',
                        type:'json',
                        data: {'cycle_id':data.id,'status':1},
                        done:function (res) {
                            if(res.code===1){
                                layer.msg(res.msg, function(){
                                    dataTable.reload();
                                });
                            }else{
                                layer.msg(res.msg, {icon: 5});
                            }
                        }
                    });
                    break;
                case 'end':
                    var data = getFirst(checkStatus.data);
                    admin.req({
                        url: "{:url('baoxiao_cycle/modify_status')}",
                        method:'post',
                        type:'json',
                        data: {'cycle_id':data.id,'status':2},
                        done:function (res) {
                            if(res.code===1){
                                layer.msg(res.msg, function(){
                                    dataTable.reload();
                                });
                            }else{
                                layer.msg(res.msg, {icon: 5});
                            }
                        }
                    });
                    break;
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });
    });
    function time2date(t) {
        var t1 = parseInt(t + '000');
        return layui.util.toDateString(t1);
    }

    function getFirst(obj){		//obj为我们的对象
        for(var key in obj){
            return obj[key];
        }
    }
</script>
</body>
</html>